package com.zjxf.base.common;

import com.google.common.base.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * created with IntelliJ IDEA
 *
 * @author: create by limu
 * Date: 2019/9/27
 * Time：10:53
 */
public class SysConst {

    public final static Long ZERO_LONG = 0L;
    public final static Integer ZERO = 0;
    public final static Integer ONE = 1;
    public final static Integer TWELVE = 12;
    public final static String SPLIT_TAG = ",";

    public final static String SHIRO_USER_SESSION_NAME = "RE_SERVICE_USER_MANGER";
    public final static Long SHIRO_SESSION_TIMEOUT = -1L;

    public static final String IP_SERVER = "http://zjxf-a.qicp.vip/apis/remote/getResourceServiceIpAndPort";    //本机部署获取本机ip地址

    public static final String HTTP_PREFIX = "http://";

    public static final String HTTP_SUFFIX = ":15808";

    public static final Long SYSTEM_ADMIN_ID = 1L;

    public static final String DEFAULT_NAME = "北京中检旭风";

    public static final String YEARS = "年";

    /**
     * session超时时间
     */
    public static final Long SESSION_TIMEOUT = 30L;
    /**
     * 加密方式
     */
    public static final String SHIRO_PASSWORD_TYPE = "md5";
    /**
     * 加密次数
     */
    public static final Integer SHIRO_PASSWORD_COUNT = 1;
    /**
     * jwt过期时间
     */
    public static final Integer JWT_EXPRIE_TIME_HOUR = 2;

    public static final String LOGIN_ERROR_PASS = ("登陆失败,用户名或密码不正确");
    public static final String LOGIN_ERROR_CODE = ("登陆失败,验证码不正确");
    public static final String SUCCESS = "操作成功";
    public static final String LOGIN_SUCCESS = "登录成功";
    public static final String DEL_SUCCESS = "删除成功";
    public static final String DATA_NOT_FOND = "数据不存在或者已经被删除";

    /**
     * 排序_属性
     */
    public static final String SORT_PROPERTIES = "updateTime";
    /**
     * 公告点赞初始值
     */
    public static final Integer LIKE_NUMBER = 0;

    /**
     * 转换文件大小
     *
     * @param fileSize 文件大小
     * @return String
     */
    public static String conversionFileSizeByMB(Long fileSize) {
        return fileSize + "MB";
    }

    public static String ZLM_SERVER_HTTP_FLV_LIVE = "ws://192.168.0.100:8903/";


    /**
     * 新闻类型
     */
    @Getter
    @AllArgsConstructor
    public enum NewsType {

        NEWS(0, "新闻"),
        BANNER(1, "轮播"),
        All(2, "全部");

        private Integer code;
        private String name;
    }

    /**
     * 审核状态
     */
    @Getter
    @AllArgsConstructor
    public enum VerifyStatus {

        IN_REVIEW(0, "审核中"),
        PASS_REVIEW(1, "已通过"),
        NO_PASS_REVIEW(2, "未通过");

        private Integer code;
        private String name;
    }

    @Getter
    @AllArgsConstructor
    public enum ProductAttrType {

        BASE_TYPE(0,"基础属性"),
        SELL_TYPE(1,"销售属性");

        private Integer code;
        private String name;
    }

    /**
     * 登录类型
     */
    @Getter
    @AllArgsConstructor
    public enum loginType {

        ADMIN(0, "admin登录"),
        SELLER(1, "seller登录"),
        APP(2, "app登录");

        private Integer code;
        private String name;
    }

    public static Optional<loginType> getLoginType(Integer code) {
        return Arrays.stream(loginType.values())
                .filter(loginType -> Objects.equal(code, loginType.getCode()))
                .findFirst();
    }

    /**
     * 用户删除状态
     */
    @Getter
    @AllArgsConstructor
    public enum DeleteState {
        UN_DELETE_STATE(0, "未删除"),
        DELETE_STATE(1, "已删除");
        private int code;
        private String name;
    }

    /**
     * 开关状态
     */
    @Getter
    @AllArgsConstructor
    public enum ONOFFType {

        ON(0, "开启"),
        OFF(1, "关闭");

        private Integer code;
        private String name;
    }

    /**
     * 显示状态
     */
    @Getter
    @AllArgsConstructor
    public enum ShowState {

        HIDE(0, "隐藏"),
        DISPLAY(1, "显示");

        private Integer code;
        private String name;
    }

    public static Optional<ShowState> getShowStateByCode(Integer code) {
        return Arrays.stream(ShowState.values())
                .filter(replyType -> Objects.equal(code, replyType.getCode()))
                .findFirst();
    }

    /**
     * 置顶状态
     */
    @Getter
    @AllArgsConstructor
    public enum TopState {

        UN_TOP(0, "不置顶"),
        TOP(1, "置顶");

        private Integer code;
        private String name;

    }


    public static Optional<TopState> getTopStateByCode(Integer code) {
        return Arrays.stream(TopState.values())
                .filter(replyType -> Objects.equal(code, replyType.getCode()))
                .findFirst();
    }

    /**
     * 阅读状态
     */
    @Getter
    @AllArgsConstructor
    public enum ReadState {

        UN_READ(0, "未读"),
        READ(1, "已读");

        private Integer code;
        private String name;
    }

    public static Optional<ReadState> getReadStateByCode(Integer code) {
        return Arrays.stream(ReadState.values())
                .filter(replyType -> Objects.equal(code, replyType.getCode()))
                .findFirst();
    }

    /**
     * 阅读状态
     */
    @Getter
    @AllArgsConstructor
    public enum ReviewState {

        IN_REVIEW(0, "审核中"),
        PASS_REVIEW(1, "已通过"),
        NO_PASS_REVIEW(2, "未通过");

        private Integer code;
        private String name;
    }

    /**
     * 发送状态
     */
    @Getter
    @AllArgsConstructor
    public enum SendState {

        UN_SENT(0, "未发送"),
        SENT(1, "已发送");

        private Integer code;
        private String name;

    }

    /**
     * 排序
     */
    @Getter
    @AllArgsConstructor
    public enum SortOrder {

        ASC("asc"),
        DESC("desc");

        private String code;
    }

    public static Optional<SortOrder> getSortOrderByType(String code) {
        return Arrays.stream(SortOrder.values())
                .filter(replyType -> StringUtils.equals(code, replyType.getCode()))
                .findFirst();
    }

    /**
     * 压缩包后缀
     */
    @Getter
    @AllArgsConstructor
    public enum CompressedPackageSuffix {
        ZIP("zip"),
        TAR("tar");
        private String name;
    }

    public static Optional<CompressedPackageSuffix> getFolderTypeByCode(Integer code) {
        return Arrays.stream(CompressedPackageSuffix.values())
                .filter(replyType -> Objects.equal(code, replyType.getName()))
                .findFirst();
    }

    /**
     * 文件扩展名 word
     */
    @Getter
    @AllArgsConstructor
    public enum ExtensionName {
        WORD2003_EDITION("doc", "word2003"),
        WORD2007_EDITION("docx", "word2007");

        private String type;
        private String name;
    }

    /**
     * 一乡一品商品状态
     */
    @Getter
    @AllArgsConstructor
    public enum OneVillageProductState {
        IS_ONE_VILLAGE(1, "是一乡一品"),
        UN_ONE_VILLAGE(0, "非一乡一品");

        private int type;
        private String name;

    }

    /**
     * 一乡一品商品状态
     */
    @Getter
    @AllArgsConstructor
    public enum RedArmyMealState {
        IS_RED_MEAl(1, "是红军粮"),
        UN_RED_MEAL(0, "非红军粮");

        private int type;
        private String name;

    }

    /**
     * 商品状态
     */
    @Getter
    @AllArgsConstructor
    public enum PutState {
        IS_PUT(1, "已上架"),
        UN_PUT(0, "未上架");

        private int type;
        private String name;

    }


    public static Optional<ExtensionName> getExtensionNameByType(String type) {
        return Arrays.stream(ExtensionName.values())
                .filter(replyType -> StringUtils.equals(type, replyType.getType()))
                .findFirst();
    }
}
